//测试Des类
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
using namespace std;
#include"des.h"
int main(){
	//生成初始密钥
	Des des;
	uint64_t key=des.generateKey();
	//printf("%x\n",key);
	cout<<hex<<setfill('0')<<setw(16)<<key<<endl;
	//明文和密文缓冲区
	char mbuf[1024]="Hello China";
	//char mbuf[1024]="Give back to Ceasar what is Ceasar's and tp God what is God's";
	uint8_t cbuf[1024];
	size_t mlen=strlen(mbuf),clen;
	//cout<<mbuf<<endl;
	//密文缓冲不足
	clen=8;
	cout<<dec<<des.encrypt(key,mbuf,mlen,cbuf,&clen)<<endl;
	cout<<clen<<endl;
	//密文缓冲充足
	cout<<des.encrypt(key,mbuf,mlen,cbuf,&clen)<<endl;
	//打印十六进制密文
	cout<<hex;
	for(size_t i=0;i<clen;i++){
		cout<<setw(2)<<(unsigned int )cbuf[i];
	}
	cout<<endl;
	//明文缓冲区不足
	mlen=8;
	cout<<dec<<des.decrypt(key,cbuf,clen,mbuf,&mlen)<<endl;
	cout<<mlen<<endl;
	//明文缓冲区充足
	cout<<des.decrypt(key,cbuf,clen,mbuf,&mlen)<<endl;
	cout<<mlen<<endl;
	//////////
	mbuf[mlen]='\0';	
	cout<<mbuf<<endl;
	return EXIT_SUCCESS;

}
